﻿using System;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Collections.Generic;

namespace FKRP.WP7.Library.SkeletonTracker
{
    [DataContract]
    public class Avatar
    {        
        public static Avatar Create(String json)
        {         
            var jsonParser = new DataContractJsonSerializer(typeof(Avatar));
     
            byte[] bytes = new System.Text.UTF8Encoding().GetBytes(json);
            using (var stream = new MemoryStream(bytes))
            {
                try
                {
                    return jsonParser.ReadObject(stream) as Avatar;
                }
                catch
                {
                    return null;
                }
            }
        }

        [DataMember(Name = "bones")] public List<Bone> Bones { get; set; }
        [DataMember(Name = "joints")] public List<Joint> Joints { get; set; }
    }
}
